home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / PowerManager DDK 1.0f1 / Interfaces&Libraries / Interfaces / MixedMode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-08  |  26.2 KB  |  708 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MixedMode.h
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Mac OS 8
  7.  
  8.      DRI:        Jim Murphy
  9.  
  10.      Copyright:    © 1992-1999 by Apple Computer, Inc., all rights reserved.
  11.  
  12.      Warning:    *** APPLE INTERNAL USE ONLY ***
  13.                  This file may contain unreleased API's
  14.  
  15.      BuildInfo:    Built by:            Scott Johnson
  16.                  On:                    10/8/99 11:26 AM
  17.                  With Interfacer:    3.0d13   (MPW PowerPC)
  18.                  From:                MixedMode.i
  19.                      Revision:        58
  20.                      Dated:            4/3/99
  21.                      Last change by:    ngk
  22.                      Last comment:    Implement GetCurrentArchitecture for pascal. Make all x86 stuff
  23.  
  24.      Bugs:        Report bugs to Radar component "System Interfaces", "Latest"
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __MIXEDMODE__
  29. #define __MIXEDMODE__
  30.  
  31. #ifndef __MACTYPES__
  32. #include <MacTypes.h>
  33. #endif
  34.  
  35.  
  36.  
  37.  
  38. #if PRAGMA_ONCE
  39. #pragma once
  40. #endif
  41.  
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45.  
  46. #if PRAGMA_IMPORT
  47. #pragma import on
  48. #endif
  49.  
  50. #if PRAGMA_STRUCT_ALIGN
  51.     #pragma options align=mac68k
  52. #elif PRAGMA_STRUCT_PACKPUSH
  53.     #pragma pack(push, 2)
  54. #elif PRAGMA_STRUCT_PACK
  55.     #pragma pack(2)
  56. #endif
  57.  
  58. /* Mixed Mode constants */
  59. /* Current Routine Descriptor Version */
  60. enum {
  61.     kRoutineDescriptorVersion    = 7
  62. };
  63.  
  64. /* MixedModeMagic Magic Cookie/Trap number */
  65. enum {
  66.     _MixedModeMagic                = 0xAAFE
  67. };
  68.  
  69. /* MixedModeState Version for CFM68K Mixed Mode */
  70. enum {
  71.     kCurrentMixedModeStateRecord = 1
  72. };
  73.  
  74. /* Calling Conventions */
  75. typedef unsigned short                     CallingConventionType;
  76. enum {
  77.     kPascalStackBased            = 0,
  78.     kCStackBased                = 1,
  79.     kRegisterBased                = 2,
  80.     kD0DispatchedPascalStackBased = 8,
  81.     kD1DispatchedPascalStackBased = 12,
  82.     kD0DispatchedCStackBased    = 9,
  83.     kStackDispatchedPascalStackBased = 14,
  84.     kThinkCStackBased            = 5
  85. };
  86.  
  87. /* ISA Types */
  88. typedef SInt8                             ISAType;
  89. enum {
  90.     kM68kISA                    = 0,
  91.     kPowerPCISA                    = 1
  92. };
  93.  
  94. enum {
  95.     kX86ISA                        = 2
  96. };
  97.  
  98. /* RTA Types */
  99. typedef SInt8                             RTAType;
  100. enum {
  101.     kOld68kRTA                    = 0 << 4,
  102.     kPowerPCRTA                    = 0 << 4,
  103.     kCFM68kRTA                    = 1 << 4
  104. };
  105.  
  106. enum {
  107.     kX86RTA                        = 2 << 4
  108. };
  109.  
  110.  
  111. #if TARGET_CPU_PPC
  112.     #define        GetCurrentISA()        ((ISAType) kPowerPCISA)
  113.     #define        GetCurrentRTA()        ((RTAType) kPowerPCRTA)
  114. #elif TARGET_CPU_68K
  115.     #define        GetCurrentISA()        ((ISAType) kM68kISA)
  116.     #if TARGET_RT_MAC_CFM
  117.         #define    GetCurrentRTA()        ((RTAType) kCFM68kRTA)
  118.     #else
  119.         #define    GetCurrentRTA()        ((RTAType) kOld68kRTA)
  120.     #endif
  121. #elif TARGET_CPU_X86
  122.     #define        GetCurrentISA()        ((ISAType) kX86ISA)
  123.     #define        GetCurrentRTA()        ((RTAType) kX86RTA)
  124. #endif
  125. #define        GetCurrentArchitecture()    (GetCurrentISA() | GetCurrentRTA())
  126.  
  127. /* Constants for specifing 68k registers */
  128. enum {
  129.     kRegisterD0                    = 0,
  130.     kRegisterD1                    = 1,
  131.     kRegisterD2                    = 2,
  132.     kRegisterD3                    = 3,
  133.     kRegisterD4                    = 8,
  134.     kRegisterD5                    = 9,
  135.     kRegisterD6                    = 10,
  136.     kRegisterD7                    = 11,
  137.     kRegisterA0                    = 4,
  138.     kRegisterA1                    = 5,
  139.     kRegisterA2                    = 6,
  140.     kRegisterA3                    = 7,
  141.     kRegisterA4                    = 12,
  142.     kRegisterA5                    = 13,
  143.     kRegisterA6                    = 14,                            /* A7 is the same as the PowerPC SP */
  144.     kCCRegisterCBit                = 16,
  145.     kCCRegisterVBit                = 17,
  146.     kCCRegisterZBit                = 18,
  147.     kCCRegisterNBit                = 19,
  148.     kCCRegisterXBit                = 20
  149. };
  150.  
  151. typedef unsigned short                     registerSelectorType;
  152. /* SizeCodes we use everywhere */
  153. enum {
  154.     kNoByteCode                    = 0,
  155.     kOneByteCode                = 1,
  156.     kTwoByteCode                = 2,
  157.     kFourByteCode                = 3
  158. };
  159.  
  160. /* Mixed Mode Routine Records */
  161. typedef unsigned long                     ProcInfoType;
  162. /* Routine Flag Bits */
  163. typedef unsigned short                     RoutineFlagsType;
  164. enum {
  165.     kProcDescriptorIsAbsolute    = 0x00,
  166.     kProcDescriptorIsRelative    = 0x01
  167. };
  168.  
  169. enum {
  170.     kFragmentIsPrepared            = 0x00,
  171.     kFragmentNeedsPreparing        = 0x02
  172. };
  173.  
  174. enum {
  175.     kUseCurrentISA                = 0x00,
  176.     kUseNativeISA                = 0x04
  177. };
  178.  
  179. enum {
  180.     kPassSelector                = 0x00,
  181.     kDontPassSelector            = 0x08
  182. };
  183.  
  184. enum {
  185.     kRoutineIsNotDispatchedDefaultRoutine = 0x00,
  186.     kRoutineIsDispatchedDefaultRoutine = 0x10
  187. };
  188.  
  189. enum {
  190.     kProcDescriptorIsProcPtr    = 0x00,
  191.     kProcDescriptorIsIndex        = 0x20
  192. };
  193.  
  194.  
  195. struct RoutineRecord {
  196.     ProcInfoType                     procInfo;                    /* calling conventions */
  197.     SInt8                             reserved1;                    /* Must be 0 */
  198.     ISAType                         ISA;                        /* Instruction Set Architecture */
  199.     RoutineFlagsType                 routineFlags;                /* Flags for each routine */
  200.     ProcPtr                         procDescriptor;                /* Where is the thing we’re calling? */
  201.     UInt32                             reserved2;                    /* Must be 0 */
  202.     UInt32                             selector;                    /* For dispatched routines, the selector */
  203. };
  204. typedef struct RoutineRecord            RoutineRecord;
  205. typedef RoutineRecord *                    RoutineRecordPtr;
  206. typedef RoutineRecordPtr *                RoutineRecordHandle;
  207. /* Mixed Mode Routine Descriptors */
  208. /* Definitions of the Routine Descriptor Flag Bits */
  209.  
  210. typedef UInt8                             RDFlagsType;
  211. enum {
  212.     kSelectorsAreNotIndexable    = 0x00,
  213.     kSelectorsAreIndexable        = 0x01
  214. };
  215.  
  216. /* Routine Descriptor Structure */
  217.  
  218. struct RoutineDescriptor {
  219.     UInt16                             goMixedModeTrap;            /* Our A-Trap */
  220.     SInt8                             version;                    /* Current Routine Descriptor version */
  221.     RDFlagsType                     routineDescriptorFlags;        /* Routine Descriptor Flags */
  222.     UInt32                             reserved1;                    /* Unused, must be zero */
  223.     UInt8                             reserved2;                    /* Unused, must be zero */
  224.     UInt8                             selectorInfo;                /* If a dispatched routine, calling convention, else 0 */
  225.     UInt16                             routineCount;                /* Number of routines in this RD */
  226.     RoutineRecord                     routineRecords[1];            /* The individual routines */
  227. };
  228. typedef struct RoutineDescriptor        RoutineDescriptor;
  229. typedef RoutineDescriptor *                RoutineDescriptorPtr;
  230. typedef RoutineDescriptorPtr *            RoutineDescriptorHandle;
  231. /* 68K MixedModeStateRecord */
  232.  
  233. struct MixedModeStateRecord {
  234.     UInt32                             state1;
  235.     UInt32                             state2;
  236.     UInt32                             state3;
  237.     UInt32                             state4;
  238. };
  239. typedef struct MixedModeStateRecord        MixedModeStateRecord;
  240. /* Macros for building static Routine Descriptors */
  241.  
  242. /* A macro which creates a static instance of a non-dispatched routine descriptor */
  243. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure)                                 \
  244.     {                                                                                \
  245.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  246.         kRoutineDescriptorVersion,                    /* version */                    \
  247.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  248.         0,                                            /* reserved 1 */                \
  249.         0,                                            /* reserved 2 */                \
  250.         0,                                            /* selector info */                \
  251.         0,                                            /* number of routines */        \
  252.         {                                            /* It’s an array */                \
  253.             {                                        /* It’s a struct */                \
  254.                 (procInfo),                            /* the ProcInfo */                \
  255.                 0,                                    /* reserved */                    \
  256.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  257.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  258.                 kFragmentIsPrepared |                /* It’s prepared */                \
  259.                 kUseNativeISA,                        /* Always use native ISA */        \
  260.                 (ProcPtr)(procedure),                /* the procedure */                \
  261.                 0,                                    /* reserved */                    \
  262.                 0                                    /* Not dispatched */            \
  263.             }                                                                        \
  264.         }                                                                            \
  265.     }
  266.  
  267. /* a macro which creates a static instance of a fat routine descriptor */
  268. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr)  \
  269.     {                                                                                \
  270.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  271.         kRoutineDescriptorVersion,                    /* version */                    \
  272.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  273.         0,                                            /* reserved */                    \
  274.         0,                                            /* reserved */                    \
  275.         0,                                            /* reserved */                    \
  276.         1,                                            /* Array count */                \
  277.         {                                            /* It’s an array */                \
  278.             {                                        /* It’s a struct */                \
  279.                 (m68kProcInfo),                        /* the ProcInfo */                \
  280.                 0,                                    /* reserved */                    \
  281.                 kM68kISA |                            /* ISA */                        \
  282.                 kOld68kRTA,                            /* RTA */                        \
  283.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  284.                 kUseCurrentISA,                        /* Use current ISA */            \
  285.                 (ProcPtr)(m68kProcPtr),                /* the procedure */                \
  286.                 0,                                    /* reserved */                    \
  287.                 0,                                    /* reserved */                    \
  288.             },                                                                        \
  289.             {                                        /* It’s a struct */                \
  290.                 (powerPCProcInfo),                    /* the ProcInfo */                \
  291.                 0,                                    /* reserved */                    \
  292.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  293.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  294.                 kFragmentIsPrepared |                /* It’s prepared */                \
  295.                 kUseCurrentISA,                        /* Always use current ISA */    \
  296.                 (ProcPtr)(powerPCProcPtr),            /* the procedure */                \
  297.                 0,                                    /* reserved */                    \
  298.                 0                                    /* reserved */                    \
  299.             }                                                                        \
  300.         }                                                                            \
  301.     }
  302.  
  303. /* Mixed Mode ProcInfos */
  304. enum {
  305.                                                                 /* Calling Convention Offsets */
  306.     kCallingConventionWidth        = 4,
  307.     kCallingConventionPhase        = 0,
  308.     kCallingConventionMask        = 0x0F,                            /* Result Offsets */
  309.     kResultSizeWidth            = 2,
  310.     kResultSizePhase            = kCallingConventionWidth,
  311.     kResultSizeMask                = 0x30,                            /* Parameter offsets & widths */
  312.     kStackParameterWidth        = 2,
  313.     kStackParameterPhase        = (kCallingConventionWidth + kResultSizeWidth),
  314.     kStackParameterMask            = (long)0xFFFFFFC0,                /* Register Result Location offsets & widths */
  315.     kRegisterResultLocationWidth = 5,
  316.     kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth), /* Register Parameter offsets & widths */
  317.     kRegisterParameterWidth        = 5,
  318.     kRegisterParameterPhase        = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  319.     kRegisterParameterMask        = 0x7FFFF800,
  320.     kRegisterParameterSizePhase    = 0,
  321.     kRegisterParameterSizeWidth    = 2,
  322.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  323.     kRegisterParameterWhichWidth = 3,                            /* Dispatched Stack Routine Selector offsets & widths */
  324.     kDispatchedSelectorSizeWidth = 2,
  325.     kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth), /* Dispatched Stack Routine Parameter offsets */
  326.     kDispatchedParameterPhase    = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth), /* Special Case offsets & widths */
  327.     kSpecialCaseSelectorWidth    = 6,
  328.     kSpecialCaseSelectorPhase    = kCallingConventionWidth,
  329.     kSpecialCaseSelectorMask    = 0x03F0
  330. };
  331.  
  332. enum {
  333.     kSpecialCase                = 0x000F                        /* (CallingConventionType) */
  334. };
  335.  
  336. enum {
  337.                                                                 /* all of the special cases enumerated.  The selector field is 6 bits wide */
  338.     kSpecialCaseHighHook        = 0,
  339.     kSpecialCaseCaretHook        = 0,                            /* same as kSpecialCaseHighHook */
  340.     kSpecialCaseEOLHook            = 1,
  341.     kSpecialCaseWidthHook        = 2,
  342.     kSpecialCaseTextWidthHook    = 2,                            /* same as kSpecialCaseWidthHook */
  343.     kSpecialCaseNWidthHook        = 3,
  344.     kSpecialCaseDrawHook        = 4,
  345.     kSpecialCaseHitTestHook        = 5,
  346.     kSpecialCaseTEFindWord        = 6,
  347.     kSpecialCaseProtocolHandler    = 7,
  348.     kSpecialCaseSocketListener    = 8,
  349.     kSpecialCaseTERecalc        = 9,
  350.     kSpecialCaseTEDoText        = 10,
  351.     kSpecialCaseGNEFilterProc    = 11,
  352.     kSpecialCaseMBarHook        = 12
  353. };
  354.  
  355.  
  356. /*
  357.     NOTES ON USING ROUTINE DESCRIPTOR FUNCTIONS
  358.     
  359.     When calling these routine from classic 68k code there are two possible intentions.
  360.  
  361.     The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  362.     the code is compiled for CFM the functions create routine descriptors that can be used by
  363.     the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  364.     these functions do nothing so that the code will run on Macintoshes that do not have a
  365.     mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  366.     into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  367.     compile it for any runtime or instruction set architecture, and it will run correctly on the
  368.     intended runtime/instruction platform. All without source changes and/or conditional source.
  369.     
  370.     The other intention is for code that "knows" that it is executing as classic 68k runtime
  371.     and is specifically trying to call code of another architecture using mixed mode. Since the
  372.     routines were designed with classic <-> CFM source compatibility in mind this second case
  373.     is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  374.     it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  375.     are only available to classic 68k callers: rigging the interfaces to allow calling them
  376.     from CFM code will result in runtime failure because no shared library implements or exports
  377.     the functions.
  378.     
  379.  
  380.     This almost appears seamless until you consider "fat" routine descriptors and the advent of
  381.     CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  382.     on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  383.     and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  384.     CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  385.     on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  386.     
  387.     By definition fat routine descriptors are only constructed by code that is aware of the 
  388.     architecture it is executing as and that another architecture exists. Source compatibility
  389.     between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  390.     is not available when building pure classic code.
  391.     
  392.     NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  393.     classic code can use the code fragment manager routine "FindSymbol" to obtain the address of 
  394.     a routine in a shared library and then construct a routine descriptor with both the CFM routine 
  395.     and classic    routine.
  396. */
  397.  
  398. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  399. EXTERN_API( UniversalProcPtr )
  400. NewRoutineDescriptor            (ProcPtr                 theProc,
  401.                                  ProcInfoType             theProcInfo,
  402.                                  ISAType                 theISA);
  403.  
  404. EXTERN_API( void )
  405. DisposeRoutineDescriptor        (UniversalProcPtr         theProcPtr);
  406.  
  407. EXTERN_API( UniversalProcPtr )
  408. NewFatRoutineDescriptor            (ProcPtr                 theM68kProc,
  409.                                  ProcPtr                 thePowerPCProc,
  410.                                  ProcInfoType             theProcInfo);
  411.  
  412. #else
  413. #define DisposeRoutineDescriptor(theProcPtr)
  414. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  415. /* Note that the call to NewFatRoutineDescriptor is undefined. */
  416. #endif  /* TARGET_OS_MAC && TARGET_RT_MAC_CFM */
  417.  
  418.  
  419. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  420. /*
  421.     The "Trap" versions of the MixedMode calls are only for classic 68K clients that 
  422.     want to load and use CFM based code.
  423. */
  424. EXTERN_API( UniversalProcPtr )
  425. NewRoutineDescriptorTrap        (ProcPtr                 theProc,
  426.                                  ProcInfoType             theProcInfo,
  427.                                  ISAType                 theISA)                                TWOWORDINLINE(0x7000, 0xAA59);
  428.  
  429. EXTERN_API( void )
  430. DisposeRoutineDescriptorTrap    (UniversalProcPtr         theProcPtr)                            TWOWORDINLINE(0x7001, 0xAA59);
  431.  
  432. EXTERN_API( UniversalProcPtr )
  433. NewFatRoutineDescriptorTrap        (ProcPtr                 theM68kProc,
  434.                                  ProcPtr                 thePowerPCProc,
  435.                                  ProcInfoType             theProcInfo)                        TWOWORDINLINE(0x7002, 0xAA59);
  436.  
  437. #endif  /* TARGET_CPU_68K && !TARGET_RT_MAC_CFM */
  438.  
  439. #if !TARGET_CPU_68K || TARGET_RT_MAC_CFM
  440. /*
  441.     CallUniversalProc is defined for all targets except classic 68k code.  This will 
  442.     catch accidental calls from classic 68K code that previously only showed up as 
  443.     linker errors.
  444. */
  445. EXTERN_API_C( long )
  446. CallUniversalProc                (UniversalProcPtr         theProcPtr,
  447.                                  ProcInfoType             procInfo,
  448.                                  ...);
  449.  
  450. EXTERN_API_C( long )
  451. CallOSTrapUniversalProc            (UniversalProcPtr         theProcPtr,
  452.                                  ProcInfoType             procInfo,
  453.                                  ...);
  454.  
  455. #endif  /* !TARGET_CPU_68K || TARGET_RT_MAC_CFM */
  456.  
  457. #if TARGET_CPU_68K
  458. EXTERN_API( OSErr )
  459. SaveMixedModeState                (MixedModeStateRecord *    stateStorage,
  460.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7003, 0xAA59);
  461.  
  462. EXTERN_API( OSErr )
  463. RestoreMixedModeState            (MixedModeStateRecord *    stateStorage,
  464.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7004, 0xAA59);
  465.  
  466. #endif  /* TARGET_CPU_68K */
  467.  
  468. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  469.  *
  470.  *    Macros for building ProcInfos.  Examples:
  471.  *    
  472.  *    
  473.  *    uppModalFilterProcInfo = kPascalStackBased
  474.  *         | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  475.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogPtr)))
  476.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
  477.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
  478.  *
  479.  *    uppDeskHookProcInfo = kRegisterBased
  480.  *         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
  481.  *         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
  482.  *
  483.  *    uppGXSpoolResourceProcInfo = kCStackBased
  484.  *         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  485.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
  486.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
  487.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
  488.  *         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  489.  *
  490.  *    uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
  491.  *
  492.  */
  493.  
  494.  
  495. /* * * * * * * * * * * * * * 
  496.  *    SIZE_CODE -     Return the size code for an object, given its size in bytes.
  497.  *        size - size of an object in bytes
  498.  */
  499. #define SIZE_CODE(size) \
  500.     (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  501.  
  502.  
  503. /* * * * * * * * * * * * * * 
  504.  *    RESULT_SIZE -     Return the result field of a ProcInfo, given the return object’s size.
  505.  *                     This is the same for all ProcInfos
  506.  *        sizeCode - size code
  507.  */
  508. #define RESULT_SIZE(sizeCode) \
  509.     ((ProcInfoType)(sizeCode) << kResultSizePhase)
  510.  
  511.  
  512. /* * * * * * * * * * * * * * 
  513.  *    STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for a simple,
  514.  *                                non-dispatched, stack based routine.
  515.  *        whichParam - which parameter
  516.  *        sizeCode - size code
  517.  */
  518. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  519.     ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  520.  
  521.  
  522. /* * * * * * * * * * * * * * 
  523.  *    DISPATCHED_STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for 
  524.  *                                            a dispatched, stack based routine.  The same
  525.  *                                            macro is used regardless of the type of
  526.  *                                            dispatching.
  527.  *        whichParam - which parameter
  528.  *        sizeCode - size code
  529.  */
  530. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  531.     ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  532.  
  533.  
  534. /* * * * * * * * * * * * * * 
  535.  *    DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE -    Return a the selector size field of a ProcInfo
  536.  *                                                for a dispatched, stack based routine.  The
  537.  *                                                same macro is used regardless of the type of
  538.  *                                                dispatching.
  539.  *        sizeCode - size code 
  540.  */
  541. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode) \
  542.     ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  543.  
  544.  
  545. /* * * * * * * * * * * * * * 
  546.  *    REGISTER_RESULT_LOCATION -        Return the Result Location field of a ProcInfo, 
  547.  *                                    given the location.
  548.  *        whichReg - which register
  549.  */
  550. #define REGISTER_RESULT_LOCATION(whichReg) \
  551.     ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  552.  
  553.  
  554. /* * * * * * * * * * * * * * 
  555.  *    REGISTER_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo for a 
  556.  *                                    register based routine.
  557.  */
  558. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode) \
  559.     ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) << \
  560.             (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  561.  
  562.  
  563. /* * * * * * * * * * * * * * 
  564.  *
  565.  *    SPECIAL_CASE_PROCINFO -     Returns the procInfo constant for the following special cases:
  566.  *    
  567.  *        High Hook & Caret Hook -  (see I-379)
  568.  *            C calling conventions, Rect on stack, pointer in A3, no return value
  569.  *        EOL Hook - (see VI-15-26)
  570.  *            Register-based; inputs in D0, A3, A4; 
  571.  *            output is Z flag of status register
  572.  *        Width Hook - (see VI-15-27)
  573.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  574.  *        NWidth Hook - (see VI-15-27)
  575.  *            Register-based; inputs in D0, D1, D2, A0, A2, A3, A4; output in D1 
  576.  *        TextWidthHook - (see VI-15-28)
  577.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  578.  *        DrawHook - (see VI-15-28)
  579.  *            Register-based; inputs in D0, D1, A0, A3, A4; no output
  580.  *        HitTestHook - (See VI-15-29)
  581.  *            Register-based; inputs in D0, D1, D2, A0, A3, A4; outputs in D0, D1, D2
  582.  *        FindWord -  (see VI-15-30)
  583.  *            Register-based; inputs in D0, D2, A3, A4; outputs in D0, D1
  584.  *        ADBRoutines - (see V-371)
  585.  *            Register-based; inputs in A0, A1, A2, D0; no outputs
  586.  *        ProtocolHandler - (see II-326)
  587.  *            Register-based; inputs in A0, A1, A2, A3, A4, D1.w; output in Z 
  588.  *        SocketListener - (see II-329)
  589.  *            Register-based; inputs in A0, A1, A2, A3, A4, D0.b, D1.w; output in Z 
  590.  *        Reclac - (see I-391)
  591.  *            Register-based; inputs in A3, D7; outputs in D2, D3, D4
  592.  *        DoText - (see I-391)
  593.  *            Register-based; inputs in A3, D3, D4, D7; outputs in A0, D0
  594.  *        GNEFilterProc - (see tech note 85)
  595.  *            Register & Stack Based; inputs in A1, D0 & on the stack; outputs on the stack
  596.  *        MenuBarHook - (see I-356)
  597.  *            Register & Stack Based; input on the stack; output in D0
  598. */
  599. #define SPECIAL_CASE_PROCINFO(specialCaseCode)            \
  600.         (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  601.  
  602.  
  603. /* * * * * * * * * * * * * * * 
  604.  *    STACK_UPP_TYPE    - used in typedefs to create ≈UPP type
  605.  *    REGISTER_UPP_TYPE - used in typedefs to create ≈UPP type
  606.  *    TVECTOR_UPP_TYPE  - used in typedefs to create ≈UPP type
  607.  *
  608.  *    Example:
  609.  *
  610.  *        typedef STACK_UPP_TYPE(ModalFilterProcPtr)         ModalFilterUPP;
  611.  *        typedef REGISTER_UPP_TYPE(IOCompletionProcPtr)     IOCompletionUPP;
  612.  *
  613.  */
  614. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  615.     /* classic 68k runtime */
  616.     #define STACK_UPP_TYPE(name)     name
  617.     #define REGISTER_UPP_TYPE(name) Register68kProcPtr
  618.     #define TVECTOR_UPP_TYPE(name)  name
  619. #elif TARGET_OS_MAC && TARGET_RT_MAC_CFM
  620.     /* PowerPC and CFM68K runtime */
  621.     #if OPAQUE_UPP_TYPES
  622.         #define STACK_UPP_TYPE(name)     struct Opaque##name##*
  623.         #define REGISTER_UPP_TYPE(name) struct Opaque##name##*
  624.         #define TVECTOR_UPP_TYPE(name)  struct Opaque##name##*
  625.     #else
  626.         #define STACK_UPP_TYPE(name)     UniversalProcPtr
  627.         #define REGISTER_UPP_TYPE(name) UniversalProcPtr
  628.         #define TVECTOR_UPP_TYPE(name)  name
  629.     #endif
  630. #elif TARGET_OS_MAC && TARGET_RT_MAC_MACHO
  631.     /* Mac OS X runtime */
  632.     #define STACK_UPP_TYPE(name)     name
  633.     #define REGISTER_UPP_TYPE(name) name
  634.     #define TVECTOR_UPP_TYPE(name)  name
  635. #else
  636.     /* other runtimes */
  637.     #define STACK_UPP_TYPE(name)     name
  638.     #define REGISTER_UPP_TYPE(name) name
  639.     #define TVECTOR_UPP_TYPE(name)  name
  640. #endif
  641.  
  642.  
  643. /* * * * * * * * * * * * * * * 
  644.  *    CALL_≈_PARAMETER_UPP  - used in Call≈Proc macros
  645.  *
  646.  *    Example:
  647.  *
  648.  *        #define CallIOCompletionProc(userRoutine, paramBlock)     \
  649.  *                CALL_TWO_PARAMETER_UPP((userRoutine), uppIOCompletionProcInfo, (paramBlock))
  650.  *
  651.  */
  652. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  653.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         CallUniversalProc(upp, procInfo)
  654.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         CallUniversalProc(upp, procInfo, (p1))
  655.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         CallUniversalProc(upp, procInfo, (p1), (p2))
  656.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3))
  657.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4))
  658.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5))
  659.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6))
  660.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7))
  661.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  662.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  663.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  664.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  665.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  666.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  667. #else
  668.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         (*(upp))()
  669.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         (*(upp))((p1))
  670.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         (*(upp))((p1), (p2))
  671.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         (*(upp))((p1), (p2), (p3))
  672.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         (*(upp))((p1), (p2), (p3), (p4))
  673.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         (*(upp))((p1), (p2), (p3), (p4), (p5))
  674.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6))
  675.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7))
  676.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  677.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  678.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  679.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  680.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  681.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  682. #endif
  683.  
  684.  
  685.  
  686.  
  687.  
  688. #if PRAGMA_STRUCT_ALIGN
  689.     #pragma options align=reset
  690. #elif PRAGMA_STRUCT_PACKPUSH
  691.     #pragma pack(pop)
  692. #elif PRAGMA_STRUCT_PACK
  693.     #pragma pack()
  694. #endif
  695.  
  696. #ifdef PRAGMA_IMPORT_OFF
  697. #pragma import off
  698. #elif PRAGMA_IMPORT
  699. #pragma import reset
  700. #endif
  701.  
  702. #ifdef __cplusplus
  703. }
  704. #endif
  705.  
  706. #endif /* __MIXEDMODE__ */
  707.  
  708.